#include "touch_sensor_ttp223.h"

uint8_t BSP_TTP223_ReadAndUpdate(volatile Device_TTP223 *dv){
    return BSP_TTP223_ReadAndUpdateIrq(dv, 0);
}

uint8_t BSP_TTP223_ReadAndUpdateIrq(volatile Device_TTP223 *dv, uint8_t inIrq){
    GPIO_TypeDef *port = dv->gpioPort;
    uint16_t pin = dv->gpioPin;
    uint8_t r1 = GPIO_ReadInputDataBit(port, pin);
    uint8_t r2;
    if(!inIrq){
        BSP_DelayMs(10);
    }else{
        BSP_DelayMsInIrq(10);
    }
    r2 = GPIO_ReadInputDataBit(port, pin);
    if(r1 == r2){
        dv->lastState = r1;
    }
    return dv->lastState;
}
